/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-04-09
 * Time:10:17
 */
public class MyList <T>{

   static class List<T>{
        T data;
        List next;
        List(){}
        List(T data){
            this.data=data;
        }
    }
     List head;

    public void insertHead(T sum)
    {
        List fw=new List(sum);
        fw.next =head;
        head=fw;
    }
    public void insertTail(T sum)
    {
       MyList.List fw=new MyList.List(sum);
        if(head==null)
        {
            head=fw;
            return;
        }
       MyList.List fw1=head;
        while(fw1.next!=null)
        {
            fw1=fw1.next;
        }
        fw1.next=fw;
    }
    public int size()
    {
        List cur=new List();
        cur=head;
        int size=0;
        while(cur!=null)
        {
            cur=cur.next;
            size++;
        }
        return size;
    }
    public void show()
    {
        List cur=new List();
        cur=head;
        while(cur!=null)
        {
            System.out.print(cur.data+" ");
            cur=cur.next;
        }
    }
    public void show(List kk)
    {
        List cur=kk;
        while(cur!=null)
        {
            System.out.print(cur.data+" ");
            cur=cur.next;
        }
    }
    //链表反转
    public void reversal()
    {
        List cur=new List();
        List curnext=new List();
        cur=head.next;
        head.next=null;
        curnext=cur.next;
        while(cur!=null)
        {
            cur.next=head;
            head=cur;
            cur=curnext;
            if(curnext!=null)
            {
                curnext=curnext.next;
            }

        }

    }


}
